package com.easyCode.feature.redis;

import com.easyCode.feature.mybaits.CustomPage;
import org.springframework.cache.interceptor.KeyGenerator;
import java.lang.reflect.Method;

/**
 * @author 大忽悠
 * @create 2022/12/21 13:03
 */
public class PageKeyGenerator implements KeyGenerator {

    @Override
    public Object generate(Object target, Method method, Object... params) {
        if(!support(params)){
            throw new RuntimeException("方法参数只能是CustomPage");
        }
        CustomPage customPage = (CustomPage) params[0];
        return customPage.getPageNum()+"-"+customPage.getPageSize();
    }

    private boolean support(Object[] params) {
        return params.length==1 && params[0] instanceof CustomPage;
    }
}
